import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

import routes from './routes'

const router = new VueRouter({
  routes
})

router.beforeEach((to, from, next) => {
  if(!to.meta.isPublic && !localStorage.token){
    Vue.prototype.$message({
      type:'info',
      message:'登录已过期，请重新登录'
    })
    return next('/login')
  }else{
    next()
  }
})

export default router
